/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.unam.aragon.repository.impl;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import mx.unam.aragon.domain.Alumno;
import mx.unam.aragon.domain.persistence.AppEntityManagerFactory;
import mx.unam.aragon.repository.AlumnoRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author erico
 */
@Repository("alumnoRepository")
public class AlumnoRepositoryImpl implements AlumnoRepository {

    private EntityManager entityManager;

    @PersistenceContext
    void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    @Transactional
    @Override
    public void save(Alumno alumno) {
        entityManager.persist(alumno);
    }

    @Transactional
    @Override
    public void merge(Alumno alumno) {
        entityManager.merge(alumno);
    }

    @Transactional
    @Override
    public List<Alumno> findAll(int firstResult, int maxResult) {
        List al = AppEntityManagerFactory.entityManagerFactory().createEntityManager().createQuery("SELECT o FROM Alumno o").setFirstResult(firstResult).setMaxResults(maxResult).getResultList();
        al.size();
        return al;
    }
}
